package interview.java.q1.internal;

import java.util.Collection;
import java.util.List;

public class AnswerResultPrinter {

  public AnswerResultPrinter(List<List<String>> result, char padChar) {
    _result = result;
    _padChar = padChar;
  }

  public void print() {
    int width = _result.stream()
        .flatMap(Collection::stream)
        .mapToInt(String::length)
        .max()
        .orElseThrow(() -> new IllegalStateException("result is empty"));

    for (List<String> line : _result) {
      for (String c : line) {
        paddingPrint(c, width);
        System.out.print(" ");
      }

      System.out.println();
    }
  }

  private void paddingPrint(String s, int width) {
//    System.out.print("0x");
    for (int i = 0; i < width - s.length(); ++i) {
      System.out.print(_padChar);
    }
    System.out.print(s);
  }

  private final List<List<String>> _result;

  private final char _padChar;
}
